import java.util.ArrayList;
import java.util.List;

public class Test {
    public static void main(String[] args) {
        String s="cbaebabacd";
        String p="abc";
        findAnagrams(s,p);
    }
    public static List<Integer> findAnagrams(String _s, String _p) {
        List<Integer> ret=new ArrayList<>();
        char[] s=_s.toCharArray();
        char[] p=_p.toCharArray();
        int len=s.length;
        int[] hash1=new int[26];
        int[] hash2=new int[26];
        for(char tmp:p){
            hash2[tmp-'a']++;
        }
        for(int left=0,right=0;right<len;right++){
            char in=s[right];
            hash1[in-'a']++;
            if(right-left+1==p.length){
                boolean flag=true;
                for(int i=0;i<26;i++){
                    if(hash1[i]!=hash2[i]){
                        flag=false;
                    }
                }
                if(flag){
                    ret.add(left);
                }
            }
            if(right-left+1>p.length){
                char out=s[left];
                hash1[out-'a']--;
                left++;
            }
        }
        System.out.println(ret);
        return ret;
    }
}
